package com.hang.ad.index.adunit;

import com.hang.ad.index.adplan.AdPlanObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdUnitObject {
    private Long unitId;
    private Integer unitStatus;
    private Integer positionType;
    private Long planId;
    private AdPlanObject adPlanObject;

    public void update(AdUnitObject adUnitObject){
        if (adUnitObject.getUnitId() != null){
            this.unitId = adUnitObject.getUnitId();
        }
        if (adUnitObject.getUnitStatus() != null){
            this.unitStatus = adUnitObject.getUnitStatus();
        }
        if (adUnitObject.getPositionType() != null){
            this.positionType = adUnitObject.getPositionType();
        }
        if (adUnitObject.getPlanId() != null){
            this.planId = adUnitObject.getPlanId();
        }
        if (adUnitObject.getAdPlanObject() != null){
            this.adPlanObject = adUnitObject.getAdPlanObject();
        }
    }

    private static boolean isKAIPING(int positionType){
        return (positionType & AdUnitConstants.POSITION_TYPE.KAIPING) > 0;
    }

    private static boolean isTIEPIAN(int positionType){
        return (positionType & AdUnitConstants.POSITION_TYPE.TIEPIAN) > 0;
    }
    private static boolean isTIEPIANMIDDLE(int positionType){
        return (positionType & AdUnitConstants.POSITION_TYPE.TIEPIAN_MIDDLE) > 0;
    }
    private static boolean isTIEPIANPAUSE(int positionType){
        return (positionType & AdUnitConstants.POSITION_TYPE.TIEPIAN_PAUSE) > 0;
    }
    private static boolean isTIEPIANPOST(int positionType){
        return (positionType & AdUnitConstants.POSITION_TYPE.TIEPIAN_POST) > 0;
    }

    public static boolean isAdSlotTypeOK(int adSlotType, int positionType){
        switch (adSlotType){
            case AdUnitConstants.POSITION_TYPE.KAIPING:
                return isKAIPING(positionType);
            case AdUnitConstants.POSITION_TYPE.TIEPIAN:
                return isTIEPIAN(positionType);
            case AdUnitConstants.POSITION_TYPE.TIEPIAN_MIDDLE:
                return isTIEPIANMIDDLE(positionType);
            case AdUnitConstants.POSITION_TYPE.TIEPIAN_PAUSE:
                return isTIEPIANPAUSE(positionType);
            case AdUnitConstants.POSITION_TYPE.TIEPIAN_POST:
                return isTIEPIANPOST(positionType);
            default:
                return false;
        }
    }
}
